package cn.edu.lcvc.ebuy_lyj.web.intercepter;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.logging.Handler;

public class LoginForAdminInterCepter extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        boolean result=false;
        HttpSession session=request.getSession();
        if (session.getAttribute("admin")!=null){  // 说明已经登录
            result=true;
        }else {
            String path = request.getContextPath();
            String basePath = request.getScheme() + "://" + request.getServerName() + ":"
                    + request.getServerPort() + path + "/";
            response.sendRedirect(basePath+"jsp/backstage/login.jsp");
        }
        return result;
    }
}
